package com.teacher.pc.controller;


import com.teacher.common.CommonResult;
import com.teacher.common.JwtTokenUtil;
import com.teacher.pojo.dto.wx.WxLoginDto;
import com.teacher.pojo.dto.wx.WxValidDto;
import com.teacher.service.IWechatUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zfm
 * @since 2021-06-15
 */
@RestController
@RequestMapping("/pc/wechat-user")
public class WechatUserController {
    @Autowired
    private IWechatUserService iWechatUserService;

    @Autowired
    private JwtTokenUtil jwtTokenUtil;

    /**
     * 微信登录
     *
     * @param dto
     * @return
     */
    @PostMapping("/login")
    @ApiOperation("微信登录")
    public CommonResult login(@RequestBody WxLoginDto dto) {
        return iWechatUserService.login(dto);
    }


    /**
     * 校验用户
     *
     * @param dto
     * @return
     */
    @PostMapping("/valid")
    @ApiOperation("校验用户")
    public CommonResult valid(@Validated @RequestBody WxValidDto dto) {
        return iWechatUserService.valid(dto);
    }

    @GetMapping("/test")
    @ApiOperation("token生成器")
    public CommonResult<String> getTestToken(String username) {
        return CommonResult.success(jwtTokenUtil.generateToken(username));
    }
}

